const Logger = require('log4js')
// 初始值或者上一次的值
let pattern = '.yyyyMMdd'
let daysToKeep = 14

const getCategory = level => {
  return {
    default: {
      appenders: ['console', 'info'],
      level: 'info'
    }
  }
}

const getAppenders = () => {
  return {
    console: { type: 'stdout' },

    info: {
      type: 'dateFile',
      filename: 'logs/log',
      pattern,
      alwaysIncludePattern: true,
      daysToKeep,
      keepFileExt: true
    }
  }
}

// init logger
const initLogger = () => {
  Logger.configure({
    appenders: getAppenders(),
    categories: getCategory(),
    pm2: true
  })
  logger = Logger.getLogger()
}

let logger = null

// 初始化logger
initLogger()

module.exports = logger
